//
//  TSComponent.swift
//  ClockWidget
//
//  Created by TSYH on 2023/10/7.
//

import UIKit

public protocol TSComponent {}

public protocol TSComponentView {
    // UI 渲染
    func renderView(with object: Any?, component: TSCollectionViewComponent, attributes: [String: Any]?)
}

public protocol TSCollectionViewSectionComponent: TSComponent {
    var cells: [TSCollectionViewCellComponent] { get }
    var headerComponent: TSCollectionViewReuseViewComponent? { get }
    var footerComponent: TSCollectionViewReuseViewComponent? { get }
    var sectionInset: UIEdgeInsets { get }
    var lineSpacing: CGFloat { get }
    var itemSpacing: CGFloat { get }
}

public extension TSCollectionViewSectionComponent {
    public var headerComponent: TSCollectionViewReuseViewComponent? { return nil }
    public var footerComponent: TSCollectionViewReuseViewComponent? { return nil }
    
    public var sectionInset: UIEdgeInsets {
        return UIEdgeInsets(top: 10, left: 16, bottom: 10, right: 16)
    }
    
    public var lineSpacing: CGFloat {
        return 12.0
    }
    
    public var itemSpacing: CGFloat {
        return 12.0
    }
}

public enum TSCollectionViewReuseViewType {
    case header
    case footer
}

public protocol TSCollectionViewReuseViewComponent: TSComponent {
    var viewClass: UICollectionReusableView.Type { get }
    var viewType: TSCollectionViewReuseViewType { get }
    var viewSize: CGSize { get }
    var reuseIdentifier: String { get }
}

public extension TSCollectionViewReuseViewComponent {
    var reuseIdentifier: String{
        return viewClass.description()
    }
}

public protocol TSCollectionViewCellComponent: TSComponent {
    var cellClass: UICollectionViewCell.Type { get }
    func cellSize(with attrubites: [String: Any]?) -> CGSize
}
